﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using UpperComputer.Application;
using YFurion.Attributes;

namespace UpperComputer.Web.Entry.Controllers
{
    /// <summary>
    /// 账户控制器
    /// </summary>
    [ApiDescriptionSettings(ApiGroupConst.DEFAULT)]
    public class AccountController : BaseController
    {
        private readonly IAuthorizeService _authorizeService;

        /// <summary>
        /// 账户服务构造函数
        /// </summary>
        /// <param name="authorizeService">认证服务</param>
        public AccountController(IAuthorizeService authorizeService)
        {
            _authorizeService = authorizeService;
        }

        /// <summary>
        /// 获取验证码
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        public async Task<VerificationResultDto> GetVerificationCode()
        {
            return await _authorizeService.GetVerificationCode();
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="input">登录数据传输对象</param>
        /// <returns></returns>
        [AllowAnonymous]
        public async Task<BaseUserResultDto> Login(LoginDto input)
        {
            LogoutDto logoutDto = await _authorizeService.Login(input);
            return logoutDto.BaseUserResultDto;
        }

        /// <summary>
        /// 退出
        /// </summary>
        /// <returns></returns>
        [OnlyCheckLogin]
        public async Task Logout()
        {
            await _authorizeService.Logout();
        }
    }
}
